/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.approve.service;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.service.CrudService;
import com.fosung.frame.modules.approve.dao.HomeApproveDao;
import com.fosung.frame.modules.approve.entity.HomeApprove;
import com.fosung.frame.modules.checkinfos.entity.Checkinfos;
import com.fosung.frame.modules.checkinfos.service.CheckinfosService;
import com.fosung.frame.modules.sys.utils.UserUtils;

/**
 * 首页Service
 * 
 * @author ygl
 * @version 2017-08-30
 */
@Service
@Transactional(readOnly = true)
public class HomeApproveService extends CrudService<HomeApproveDao, HomeApprove> {

	@Autowired
	private CheckinfosService checkinfosService;
	
	public HomeApprove get(String id) {
		return super.get(id);
	}
	
	@Transactional(readOnly = false)
	public void save(HomeApprove homeApprove) {
		super.save(homeApprove);
	}
	
	/**
	 * 首页功能 查询组织生活计划当前组织下所有待审批数据
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public List<HomeApprove> findOrganizeLifeJhList(HomeApprove homeApprove) {
		return dao.findOrganizeLifeJhList(homeApprove);
	}
	

	/**
	 * 首页功能 查询积分申请计划当前组织下所有待审批数据
	 * @param homeApprove
	 * @return
	 */
	public List<HomeApprove> findOrganizeLifeJfList(HomeApprove homeApprove) {
		return dao.findOrganizeLifeJfList(homeApprove);
	}

	/**
	 * 组织生活活动积分审批查询页面
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public Page<HomeApprove> findActivityApprovePage(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findActivityApprovePage(homeApprove));
		return page;
	}

	/**
	 * 党组织积分审批查询页面
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public Page<HomeApprove> findPartyApprovePage(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findPartyApprovePage(homeApprove));
		return page;
	}

	/**
	 * 党员积分审批查询页面
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public Page<HomeApprove> findPersonApprovePage(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findPersonApprovePage(homeApprove));
		return page;
	}

	/**
	 * 组织生活计划管理功能查询页面
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public Page<HomeApprove> findPlanApprovePage(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findPlanApprovePage(homeApprove));
		return page;
	}

	/**
	 * 更新组织生活表审核状态
	 * 
	 * @param homeApprove
	 */
	@Transactional(readOnly = false)
	public void updateApproveShState(HomeApprove homeApprove) {
		dao.updateApproveShState(homeApprove);
	}

	/**
	 * 更新组织生活表计划状态  保存计划审核意见
	 * 
	 * @param homeApprove
	 */
	@Transactional(readOnly = false)
	public void updateApproveJhState(HomeApprove homeApprove) {
		dao.updateApproveJhState(homeApprove);
		Checkinfos info = new Checkinfos(homeApprove.getId(),UserUtils.getUser().getId(),homeApprove.getState(),null);
		checkinfosService.saveShjhyj(info);
	}

	/**
	 * 审批意见操作
	 * @param homeApprove
	 */
	@Transactional(readOnly = false)
	public void updateShyj(HomeApprove homeApprove) {
		checkinfosService.saveShjhyj(homeApprove.getCheckinfos());
		homeApprove.setState(homeApprove.getCheckinfos().getApproveStatus());
		dao.updateApproveJhState(homeApprove);
	}

	public Page<HomeApprove> findPartyLifeByOrgId(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findPartyLifeByOrgId(homeApprove));
		return page;
	}

	/**
	 * 组织活动统计列表
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public Page<HomeApprove> findPlanStatisticPage(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findPlanStatisticPage(homeApprove));
		return page;
	}

	public List<HomeApprove> findPlanStatisticChart(HomeApprove homeApprove) {
		return dao.findPlanStatisticChart(homeApprove);
	}

	/**
	 * 党员统计分析 党员查看详情
	 * @param page
	 * @param homeApprove
	 * @return
	 */
	public Page<HomeApprove> findPersonLifeById(Page<HomeApprove> page, HomeApprove homeApprove) {
		homeApprove.setPage(page);
		page.setList(dao.findPersonLifeById(homeApprove));
		return page;
	}
	

}